#!/bin/sh
# - runtime
# - nr_threads
# - ip
# - test
# - send_size
# - socket_buffer_size
# - delay
# - iterations

## Netperf is a benchmark that can be use to measure various aspect of
## networking performance. The primary foci are bulk (aka unidirectional)
## data transfer and request/response performance using either TCP
## or UDP and the Berkeley Sockets interface.

. $LKP_SRC/lib/reproduce-log.sh
. $LKP_SRC/lib/wait.sh
setup_wait

export PATH=$BENCHMARK_ROOT/netperf/bin:$PATH

[ "${test#*SCTP}" != "$test" ] && log_cmd modprobe sctp 2>/dev/null
sleep 1

[ -n "$send_size" ] && send_size="-m $send_size"
[ -n "$socket_buffer_size" ] && socket_buffer_size="-s $socket_buffer_size -S $socket_buffer_size"

if [ -n "$send_size" ] || [ -n "$socket_buffer_size" ]; then
    test_options="-- $send_size $socket_buffer_size"
fi

[ -n "$direct_server_ips" ] && server=$direct_server_ips
[ -z "$server" ] && {
	if [ "$ip" = 'ipv6' ]; then
		server=::1
	else
		server=127.0.0.1
	fi
}
server=${server%% *}

opt_ip=
[ "$ip" = 'ipv4' ] && opt_ip='-4'
[ "$ip" = 'ipv6' ] && opt_ip='-6'

run_netperf()
{
	[ -n "$delay" ] && $WAIT_POST_TEST_CMD --timeout "$delay"

	for i in $(seq $nr_threads)
	do
		log_eval "netperf $opt_ip -H $server -t $test -c -C -l $runtime $test_options &"
	done

	log_eval wait
}

run_for_iterations()
{
	for i in $(seq 1 $iterations); do
		echo "Iterations: $i"
		run_netperf
	done
}

if [ -n "$iterations" ]; then
	run_for_iterations
else
	run_netperf
fi

# Comments from Jesse Brandeburg <jesse.brandeburg@intel.com>
# -P0 -- -r 64k -b 10
# -T0,0
